Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove explicit Box::new calls in memory mapping #34

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

breqdev
Copy link
Owner

@breqdev breqdev commented Nov 22, 2023

This makes the syntax for defining a memory map much less verbose.

Old:

let memory = BranchMemory::new()
  .map(0x0000, Box::new(ram))
  .map(0x4000, Box::new(io))
  .map(0x8000, Box::new(rom));

New:

let memory = BranchMemory::new()
  .map(0x0000, ram)
  .map(0x4000, io)
  .map(0x8000, rom);

This applies to Banked and Branch memory types.

This is accomplished by using impl syntax, replacing memory: Box<dyn Memory> with memory: impl Memory + 'static and constructing the Box within the .bank and .map functions. The 'static is needed to ensure the Box's contents live long enough.

@breqdev breqdev requested a review from ava-silver November 22, 2023 23:13
@breqdev breqdev self-assigned this Nov 22, 2023
Copy link
Collaborator

@ava-silver ava-silver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@breqdev breqdev merged commit f1595eb into main Nov 22, 2023
5 checks passed
@ava-silver ava-silver deleted the bc/memory-api-implied-box branch December 30, 2023 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants